<template>
  <div class="root">
      <div class="background">
        <img src="@/assets/images/logo.png" alt=""/>
        <div class="welcome">
          欢迎进入猿之家天眼教学管理系统
        </div>
      </div>
      <div class="login-content">
        <div class="title">登录</div>
        <div class="input-content">
          <div>用户名:</div>
          <input type="text" placeholder="请输入您的用户名" v-model="username">
        </div>
        <div class="input-content">
          <div>密码:</div>
          <input type="password" placeholder="请输入您的密码" v-model="password">
        </div>
        <div class="login-button" @click="login">
          登录
        </div>
      </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import {loginAPI} from "@/network/user/user";
import { ElMessage } from "element-plus";
import router from "@/router";
import {getSYSDictAPI} from "@/network/sys-dict";
import { useSysDictStore } from "@/store/store-sys-dict-pinia";

const sysDictStore = useSysDictStore()


const username=ref('')
const password=ref('')

const login=()=>{
  loginAPI(
      {
        username:username.value,
        password:password.value
      }
  ).then(res=>{
    if(res.code===0){
      ElMessage.success(res.message)
      router.push("/home")
      // 获取系统字典
      sysDictStore.getSysDict()
    }else{
      ElMessage.error(res.message)
    }
  })
}
</script>

<style scoped lang="less">
.root {
  .background{
    width: 100%;
    height: 520.5px;
    background-image: url("@/assets/images/login/background.png");
    background-repeat: no-repeat; /* 图片不重复显示 */
    background-position: center center; /* 图片居中显示 */
    background-size: cover; /* 图片自动调整大小以适应元素的尺寸 */
    img{
      margin-top: 50px;
      width: 70px;
    }
    .welcome{
      width: 100%;
      height: 100%;
      color: white;
      font-size: 32px;
      font-weight: bold;
      text-align: center;
    }
  }
  .login-content{
    position: absolute;
    top: 450px;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 452px;
    height: 500px;
    background-color: white;
    border-radius: 10px;
    box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.5);
    .title{
      width: 100%;
      height: 60px;
      line-height: 60px;
      text-align: center;
      font-size: 24px;
      color: #2D3748;
      font-weight: bold;
      margin-top: 40px;
    }
    .input-content{
      width: 80%;
      height: 100px;
      margin: 20px auto;
      line-height: 50px;
      font-size: 16px;
      color: #2D3748;
      >div{
        text-align: left;
        font-weight: bold;
      }
      input{
        width: 90%;
        height: 50px;
        border: 1px solid #E2E8F0;
        border-radius: 10px;
        outline: none;
        padding-left: 20px;
      }
    }
    .login-button{
      background-color: #4FD1C5;
      width: 75%;
      height: 50px;
      line-height: 50px;
      text-align: center;
      color: white;
      font-size: 16px;
      font-weight: bold;
      border-radius: 10px;
      margin: 50px auto;
      :hover{
        cursor: pointer;
      }
    }
  }
}
</style>